package com.corona.game;

import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.corona.Game;

/* compiled from: Player.java */
/* access modifiers changed from: package-private */
/* loaded from: pokewilds.jar:com/pkmngen/game/CutTreeAnim.class */
public class CutTreeAnim extends Action {
    int timer = 0;
    Tile tile;
    Sprite left;
    Sprite right;
    int offsetX;

    public CutTreeAnim(Game game, Tile tile, Action nextAction) {
        super(new Object[0]);
        this.offsetX = 0;
        this.tile = tile;
        this.nextAction = nextAction;
        if (this.tile.nameUpper.equals("tree_savanna1")) {
            this.offsetX = 16;
        }
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        if (this.timer >= 13) {
            if (this.timer == 13) {
                game.insertAction(new PlayMusic("cut1", (Action) null));
            } else if (this.timer >= 19) {
                if (this.timer == 19) {
                    game.map.tiles.remove(this.tile.position);
                    String name = this.tile.name;
                    if (name.equals("grass2")) {
                        name = "green1";
                    } else if (name.equals("grass3")) {
                        name = "snow1";
                    } else if (name.equals("grass_sand1")) {
                        name = "sand1";
                    } else if (name.equals("grass4")) {
                        name = "green1";
                    } else if (name.equals("grass_sand3")) {
                        name = "desert4";
                    } else if (name.equals("grass_graveyard1")) {
                        name = "green11";
                    } else if (name.equals("tree5")) {
                        name = "green1";
                    } else if (name.equals("tree_large1")) {
                        name = "green1";
                        for (Vector2 position : new Vector2[]{this.tile.position.cpy().add(16.0f, 0.0f), this.tile.position.cpy().add(16.0f, 16.0f), this.tile.position.cpy().add(0.0f, 16.0f)}) {
                            Tile newTile = game.map.tiles.get(position);
                            newTile.name = name;
                            newTile.nameUpper = "";
                            newTile.overSprite = null;
                            newTile.init();
                            newTile.updateMiniMap(game);
                        }
                        this.tile.overSprite = this.tile.sprite;
                    } else if (this.tile.nameUpper.equals("aloe_large1")) {
                        name = "green1";
                        for (Vector2 position2 : new Vector2[]{this.tile.position.cpy().add(16.0f, 0.0f), this.tile.position.cpy().add(16.0f, 16.0f), this.tile.position.cpy().add(0.0f, 16.0f)}) {
                            Tile newTile2 = game.map.tiles.get(position2);
                            newTile2.name = name;
                            newTile2.nameUpper = "";
                            newTile2.overSprite = null;
                            newTile2.init();
                            newTile2.updateMiniMap(game);
                        }
                    } else if (name.contains("bridge") && this.tile.nameUpper.equals("")) {
                        name = this.tile.unSquish();
                        if (name == null) {
                            name = "water2";
                        }
                        this.tile.overSprite = this.tile.sprite;
                        Tile down = game.map.tiles.get(this.tile.position.cpy().add(0.0f, -16.0f));
                        if (down != null && down.belowBridge) {
                            down.belowBridge = false;
                            down.isSolid = false;
                        }
                    }
                    Tile newTile3 = new Tile(name, this.tile.position.cpy(), true, this.tile.routeBelongsTo);
                    newTile3.biome = this.tile.biome;
                    game.map.tiles.put(this.tile.position.cpy(), newTile3);
                    newTile3.updateMiniMap(game);
                    if (this.tile.nameUpper.contains("warp_tile")) {
                        DrawMiniMap.warpTiles.remove(this.tile.position.cpy());
                    }
                    if (newTile3.routeBelongsTo != null) {
                        newTile3.routeBelongsTo.storedPokemon.clear();
                    }
                    game.mapBatch.draw(this.tile.sprite, this.tile.sprite.getX(), this.tile.sprite.getY());
                    game.mapBatch.draw(this.tile.overSprite, this.tile.overSprite.getX(), this.tile.overSprite.getY());
                } else if (this.timer == 20) {
                    TextureRegion[][] tempRegion = new Sprite(this.tile.overSprite).split(((int) this.tile.overSprite.getWidth()) / 2, (int) this.tile.overSprite.getHeight());
                    this.left = new Sprite(tempRegion[0][0]);
                    this.left.setPosition((this.tile.position.x - 2.0f) - ((float) this.offsetX), this.tile.position.y);
                    this.right = new Sprite(tempRegion[0][1]);
                    this.right.setPosition(((this.tile.position.x + 2.0f) - ((float) this.offsetX)) + ((float) (((int) this.tile.overSprite.getWidth()) / 2)), this.tile.position.y);
                    game.mapBatch.draw(this.left, this.left.getX(), this.left.getY());
                    game.mapBatch.draw(this.right, this.right.getX(), this.right.getY());
                } else if (this.timer < 37) {
                    game.mapBatch.draw(this.left, this.left.getX(), this.left.getY());
                    game.mapBatch.draw(this.right, this.right.getX(), this.right.getY());
                } else if (this.timer >= 39) {
                    if (this.timer == 39) {
                        this.left.translateX(-2.0f);
                        this.right.translateX(2.0f);
                        game.mapBatch.draw(this.left, this.left.getX(), this.left.getY());
                        game.mapBatch.draw(this.right, this.right.getX(), this.right.getY());
                    } else if (this.timer < 41) {
                        game.mapBatch.draw(this.left, this.left.getX(), this.left.getY());
                        game.mapBatch.draw(this.right, this.right.getX(), this.right.getY());
                    } else if (this.timer >= 43) {
                        if (this.timer == 43) {
                            this.left.translateX(-2.0f);
                            this.right.translateX(2.0f);
                            game.mapBatch.draw(this.left, this.left.getX(), this.left.getY());
                            game.mapBatch.draw(this.right, this.right.getX(), this.right.getY());
                        } else if (this.timer < 45) {
                            game.mapBatch.draw(this.left, this.left.getX(), this.left.getY());
                            game.mapBatch.draw(this.right, this.right.getX(), this.right.getY());
                        } else if (this.timer >= 47) {
                            if (this.timer == 47) {
                                this.left.translateX(-2.0f);
                                this.right.translateX(2.0f);
                                game.mapBatch.draw(this.left, this.left.getX(), this.left.getY());
                                game.mapBatch.draw(this.right, this.right.getX(), this.right.getY());
                            } else if (this.timer >= 49) {
                                game.actionStack.remove(this);
                                game.insertAction(this.nextAction);
                            }
                        }
                    }
                }
            }
        }
        this.timer++;
    }
}
